<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ include file="/common/common.jsp" %>
<html>
<head>
    <meta charset="UTF-8">
    <title>添加会员卡</title>
    <meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
    <!-- Bootstrap 3.3.4 -->
    <link href="${ctx}/static/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <link href="${ctx}/static/plugins/validationEngine/css/validationEngine.jquery.css" rel="stylesheet" type="text/css">
    <!-- FontAwesome 4.3.0 -->
    <style type="text/css">
		.conetnt_div{
			width: 70%;
			margin-left: auto;
			margin-right: auto;
		}
		.conetnt_div table {
			width: 100%;
			height:300px;
			margin: 30px 0px 0px 0px;
		}
		.conetnt_div table td{
			height: 30px;
			line-height: 30px;
			padding: 0px 10px 0px 10px
		}
		.conetnt_div table tr{
			margin-top:20px;
		}
		.button_td{
			text-align: center;
		}
    </style>
</head>
<body>
<div class="wrapper">
	<div class = "conetnt_div">
		<form class="form-horizontal" id="add_member_cardv">
			<table>
				<tr>
					<td>
						<label for="card_innerCode">IC卡号：</label>
					</td>
					<td colspan="2">
						<input type="text" class="form-control validate[required,maxSize[30]]" id="card_innerCode" placeholder="IC卡号">
					</td>
				</tr>
				<tr>
					<td>
						<label for="card_outerCode">条形码：</label>
					</td>
					<td colspan="2">
						<input type="text" class="form-control validate[required,maxSize[30]]" id="card_outerCode" placeholder="条形码">
					</td>
				</tr>
				<tr>
					<td colspan="3" class="button_td">
						<button type="button"  class="btn btn-primary" id="gs_submitbtn" onClick="addCardsubmit()"><i class="fa fa-download space"></i>添加会员卡</button>
					</td>
				</tr>
			</table>
		</form>
	</div>
</div>
<!-- jQuery 2.1.4 -->
<script src="${ctx}/static/plugins/jQuery/jQuery-2.1.4.min.js"></script>
<!--Bootstrap v3.3.4-->
<!-- datatable -->
<script src="${ctx}/static/plugins/layer/layer.js"></script>
<script src="${ctx}/static/plugins/validationEngine/jquery.validationEngine-zh_CN.js"></script>
<script src="${ctx}/static/plugins/validationEngine/jquery.validationEngine.js"></script>
<script>
//添加会员卡
function addMemberCrad(){
	var flag = $("#add_member_cardv").validationEngine("validate");
	if(!flag){
		$('#gs_submitbtn').attr("disabled", false);
	}
	return flag;
}
//执行添加会员卡提交
function addCardsubmit(){
	var flag = addMemberCrad();
	if(!flag){
		return;
	}
	$('#gs_submitbtn').attr("disabled", true);
	var card_innerCode = $('#card_innerCode').val();
	var card_outerCode = $('#card_outerCode').val();
	$.ajax({
		type:'post', 
		url:"${ctx}/api/membercard/addMemberCradSubmit",
		data:{"innerCode":card_innerCode,"outerCode":card_outerCode},
		dataType:'json',
		error:function(){
			layer.alert("服务端错误,请检查网络");
			$('#gs_submitbtn').attr("disabled", false);
		},
		success:function(data){
			if(data.code == 200){
				layer.msg('添加成功');
				$('#gs_submitbtn').attr("disabled", false);
				setTimeout(function(){
					var index = parent.layer.getFrameIndex(window.name);
					parent.layer.close(index);
				},1000);
			}else{
				layer.msg(data.msg);
				$('#gs_submitbtn').attr("disabled", false);
			}
		}
	});
}
function closepage(){
	var index = parent.layer.getFrameIndex(window.name);
	parent.layer.close(index);
}
</script>
</body>
</html>